<!--
// +----------------------------------------------------------------------
// | Created by PHPstorm: JRKAdmin框架 [ JRKAdmin ]
// +----------------------------------------------------------------------
// | Copyright (c) 2019~2022 [LuckyHHY] All rights reserved.
// +----------------------------------------------------------------------
// | SiteUrl: http://www.luckyhhy.cn
// +----------------------------------------------------------------------
// | Author: LuckyHhy <jackhhy520@qq.com>
// +----------------------------------------------------------------------
// | Date: 2020/3/14 0014-14:59
// +----------------------------------------------------------------------
// | Description:
// +----------------------------------------------------------------------
*-->

{extend name='public/base' /}


{block name="content"}

<div class="layui-col-md12">


    <div class="layui-card">
        <div class="layui-card-header" style="line-height: 55px;">
            <div class="layui-btn-container do_btn">
                <!--按钮区-->
                <button class="layui-btn layui-btn-sm" data-type="add"><i class="layui-icon"></i>新增配置</button>

                <button class="layui-btn layui-btn-sm layui-btn-primary" data-type="reload"><i class="fa fa-refresh"></i> 刷新</button>

            </div>
        </div>
        <div class="layui-card-body">

            <!--表格区-->

            <div class="yys-fluid yys-wrapper">
                <div class="layui-row lay-col-space20">
                    <div class="layui-cos-xs12 layui-col-sm12 layui-col-md12 layui-col-lg12">
                        <section class="yys-body">
                            <div class="yys-body-content clearfix changepwd">
                                <div class="layui-col-lg12 layui-col-md10 layui-col-sm12 layui-col-xs12" style="width:100%">
                                    <div class="user-tables">
                                        <table id="tableFilter" lay-filter="tableFilter"> </table>
                                    </div>
                                </div>
                            </div>
                        </section>
                    </div>
                </div>
            </div>


        </div>
    </div>

</div>


{/block}


{block name="js"} <!--js处理区-->


<!--模板-->
<script type="text/html" id="operationTpl">
    <a data-clipboard-text="{d.key}" class="copy layui-btn layui-bg-gray" title="点击复制地址" style="top:0;right:0;background:none!important"><i class="fa fa-copy"></i></a>
</script>

<script>

    layui.use(['element', 'table', 'form', 'jquery', 'lucky'], function () {
        var element = layui.element;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;
        var lucky=layui.lucky;

        form.render();

        // layer.load(2);
        table.render({
            elem: '#tableFilter',
            url:"{:url('setting/setlist')}",
            //toolbar: '#toolbarDemo',
            even: true, //开启隔行背景
            id:'table_id',
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip','last'] //自定义分页布局
                //,curr: 5 //设定初始在第 5 页
                ,groups: 5 //只显示 1 个连续页码
                ,first: false //不显示首页
                ,last: false //不显示尾页
                ,limit:30
                ,limits:[20,30,40,50,60]
            },
            height: 'full-100',
            text: {
                none: '暂无相关数据'
            },
            cols: [[
                {field: 'key',  title: '配置key',width:200},
                {field: 'value', width: 400, title: '配置值',event: 'revalue'},
                {field: 'copy',style:'cursor: pointer;',title: '调用方式',minWidth:350},
                {field: 'desc',style:'cursor: pointer;',title: '描述',width:200,event: 'desc'}
            ]],
            done: function (res) {
                layer.closeAll('loading');
            }
        });


        /**
         * 表格搜索
         */
        form.on('submit(search)', function (obj) {
            lucky.CreateSearch("table_id",obj.field); //查询
            return false;
        });


        /**
         * 监听单行工具操作
         */
        table.on('tool(tableFilter)', function (obj) {
            var data = obj.data;
            // console.log(JSON.stringify(data));
            var _key=data.key;
            var layEvent = obj.event;
            if(layEvent==="revalue"){
                layer.prompt({
                    formType: 2
                    ,title: '修改配置值'
                    ,value: data.value
                }, function(value, index){
                    if(value==null || value=="" || value==undefined){
                        layer.msg("配置值不能为空",{kin: 'layui-layer-lan', icon:5,time:1000},function () {
                            layer.close(index);
                        });
                        return ;
                    }
                    $.post("{:url('setting/change')}",{type:1,key:_key,value:value},function (res) {
                        if (res.code==1){
                            layer.close(index);
                            layer.msg(res.msg,{kin: 'layui-layer-lan', icon:1,time:1000},function () {
                                //同步更新表格和缓存对应的值
                                obj.update({
                                    value: value
                                });
                            });
                        }else {
                            layer.msg(res.msg,{kin: 'layui-layer-lan', icon:5,time:1000},function () {
                                layer.close(index);
                            });
                        }
                    },'json');
                });
            }else if (layEvent==="desc"){
                layer.prompt({
                    formType: 2
                    ,title: '修改配置描述'
                    ,value: data.desc
                }, function(value, index){
                    if(value==null || value=="" || value==undefined){
                        layer.msg("配置值不能为空",{kin: 'layui-layer-lan', icon:5,time:1000},function () {
                            layer.close(index);
                        });
                        return ;
                    }
                    $.post("{:url('setting/change')}",{type:2,key:_key,value:value},function (res) {
                        if (res.code==1){
                            layer.close(index);
                            layer.msg(res.msg,{kin: 'layui-layer-lan', icon:1,time:1000},function () {
                                //同步更新表格和缓存对应的值
                                obj.update({
                                    desc: value
                                });
                            });
                        }else {
                            layer.msg(res.msg,{kin: 'layui-layer-lan', icon:5,time:1000},function () {
                                layer.close(index);
                            });
                        }
                    },'json');
                });
            }
        });


        var active = {
            add: function(){
                lucky.CreateForm("添加配置",'50%','55%',"{:url('setting/addSet')}","table_id");
            },
            reload: function(){
                lucky.CreateReload("table_id");
            }
        };

        $('.do_btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });



    });

</script >


{/block}
